{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# diff学习成果分享\n",
    "## 综述\n",
    "diff命令用来对比文件或目录的差异。使用`diff --help`显示帮助信息。\n",
    "## 参数\n",
    "-q,--brief:仅报告对比结果，不报告具体内容\n",
    "\n",
    "-s:使用该参数时会报告文件相同（两个文件一致时默认不输出任何内容）\n",
    "\n",
    "-c,-C NUM:如果有不同内容，分别将相同的内容打印出来，打印上下NUM行\n",
    "\n",
    "-u,-U NUM:如果有不同内容，仅打印一次相同内容，打印上下NUM行\n",
    "\n",
    "-i:忽略文件内容的大小写\n",
    "\n",
    "-E:忽略制表符差异\n",
    "\n",
    "-Z:忽略行末尾的空格差异\n",
    "\n",
    "--strip-trailing-cr:忽略行末的回车\n",
    "\n",
    "-b:忽略空格数造成的差异（多个连续空格和一个空格相同）\n",
    "\n",
    "-w:忽略所有空格（TAB和回车符也会被忽略）\n",
    "\n",
    "-B:忽略所有空行\n",
    "\n",
    "-I=RE:若某行能够满足正则表达式条件，则忽略该行\n",
    "\n",
    "-N:如果某文件仅在一个路径中存在，则和空文件比较（默认给出提示）\n",
    "\n",
    "-p:若出现差异则显示函数名（比较的文件是C/C++源码时）\n",
    "\n",
    "-r:递归比较目录下的所有文件\n",
    "\n",
    "-S=FILE:比较两个路径下所有文件时，从指定文件开始。在有较多文件需要比较而且有中断时较为有用\n",
    "\n",
    "-y:以分列的形式显示不同文件\n",
    "\n",
    "-W:可以与-y参数联用，指定列宽，默认130\n",
    "\n",
    "--ignore-file-name-case:忽略文件名的大小写，仅有大小写区别的认为是同一个文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#参数举例\n",
    "#仅对比结果\n",
    "import os\n",
    "print(''.join(os.popen('diff -q file1 file2 1>/dev/null ; echo $?').readlines()))\n",
    "print(''.join(os.popen('diff -q file1 file1.bak 1>/dev/null ; echo $?').readlines()))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
